<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
	<title>用户管理-修改</title>
	#@head()
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
	<div class="row">
		<div class="col-sm-12">
			<div class="ibox float-e-margins">
				<div class="ibox-content">
					<form class="form-horizontal m-t" id="form" onsubmit="return submitForm()">
						<input name="bean.id" id="id" type="hidden" value="#(bean.id)">

						<div class="form-group">
							<label class="col-sm-3 control-label">姓名：</label>
							<div class="col-sm-8">
								<input id="name" name="bean.name" value="#(bean.name)" class="form-control re" type="text">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">用户名：</label>
							<div class="col-sm-8">
								<input id="username" name="bean.username" value="#(bean.username)" class="form-control" type="text">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">密码：</label>
							<div class="col-sm-8">
								<input id="password" name="bean.password" value="" class="form-control" type="password" placeholder="默认不修改">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">部门：</label>
							<div class="col-sm-8">
								<input id="deptId" name="bean.deptId" class="hidden" value="#(dept.id)">
								<input id="deptName" name="deptName" class="form-control" type="text" style="cursor: pointer;" value="#(dept.name)" onclick="openDept()" readonly="readonly" placeholder="所属部门">
							</div>
						</div>

						<div class="form-group">
							<label class="col-sm-3 control-label">E-mail：</label>
							<div class="col-sm-8">
								<input id="email" name="bean.email" value="#(bean.email)" class="form-control" type="email">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">状态:</label>
							<div class="col-sm-8 i-checks">
								<label class="radio-inline"> 
									<input type="radio" name="bean.status" value="1" #if(bean.status == 1) checked #end /> 正常
								</label> 
								<label class="radio-inline"> 
									<input type="radio" name="bean.status" value="0" #if(bean.status == 0) checked #end /> 禁用
								</label>
							</div>
						</div>

						<input type="hidden" name="roleIds" id="roleIds">
						<div class="form-group">
							<label class="col-sm-3 control-label">角色</label>
							<div class="col-sm-8 i-checks">
								#for(item : roleList)
									<label class="checkbox-inline">
										<input name="role" type="checkbox" value="#(item.id)" #for(roleId : roleIds) #if(roleId == item.id) checked #end #end>#(item.roleName)
									</label>
								#end
							</div>
						</div>

						<div class="form-group">
							<div class="col-sm-8 col-sm-offset-3">
								<button type="submit" class="btn btn-primary">提交</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>

</div>
	
	#@footer()
	
<script type="text/javascript">
	var ctx = '';
	$().ready(function() {
		validateRule();
	});

	function getCheckedRoles() {
		var adIds = "";
		$("input:checkbox[name=role]:checked").each(function(i) {
			if (0 == i) {
				adIds = $(this).val();
			} else {
				adIds += ("," + $(this).val());
			}
		});
		return adIds;
	}

    function submitForm() {
        save();
        return false;
    }

	function save() {
		$("#roleIds").val(getCheckedRoles());
		$.ajax({
			cache : true,
			type : "POST",
			url :  "update",
			data : $('#form').serialize(),// 你的formid
			async : false,
			error : function(request) {
				parent.layer.alert("Connection error");
			},
			success : function(data) {
				if (data.code == 0) {
					parent.layer.msg("操作成功");
					parent.reLoad();
					var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
					parent.layer.close(index);

				} else {
					parent.layer.alert(data.msg)
				}

			}
		});

	}
	function validateRule() {
		var icon = "<i class='fa fa-times-circle'></i> ";
		$("#form").validate({
			rules : {
				name : {
					required : true
				},
				username : {
					required : true,
					minlength : 2,
					remote : {
						url : ctx +"/sys/user/exit", // 后台处理程序
						type : "post", // 数据发送方式
						dataType : "json", // 接受数据格式
						data : { // 要传递的数据
							username : function() {
								return $("#username").val();
							}
						}
					}
				},
				password : {
					required : false,
					minlength : 6
				},
				confirm_password : {
					required : true,
					minlength : 6,
					equalTo : "#password"
				},
				email : {
					required : true,
					email : true
				},
				topic : {
					required : "#newsletter:checked",
					minlength : 2
				},
				agree : "required"
			},
			messages : {

				name : {
					required : icon + "请输入姓名"
				},
				username : {
					required : icon + "请输入您的用户名",
					minlength : icon + "用户名必须两个字符以上",
					remote : icon + "用户名已经存在"
				},
				password : {
					required : icon + "请输入您的密码",
					minlength : icon + "密码必须6个字符以上"
				},
				confirm_password : {
					required : icon + "请再次输入密码",
					minlength : icon + "密码必须6个字符以上",
					equalTo : icon + "两次输入的密码不一致"
				},
				email : icon + "请输入您的E-mail",
			}
		})
	}

	var openDept = function(){
		layer.open({
			type:2,
			title:"选择部门",
			area : [ '300px', '450px' ],
			content:"../dept/treeView"
		})
	}
	function loadDept( deptId,deptName){
		$("#deptId").val(deptId);
		$("#deptName").val(deptName);
	}
</script>
</body>
</html>


